package com.net.model.interceptor;

import android.text.TextUtils;

import com.drug.lib.util.SPManager;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 版权：星云飞救公司 版权所有
 *
 * @author zhouhequan
 * 版本：1.0
 * 创建日期：2021/10/25 or 9:46
 * 描述：token过期处理拦截器
 */
public class TokenInterceptor implements Interceptor {
    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = chain.request();
        if (!TextUtils.isEmpty(SPManager.getToken())) {
            Request.Builder builder = request.newBuilder();
            builder.addHeader("token", SPManager.getToken());
            Request newRequest = builder.build();
            return chain.proceed(newRequest);
        }
        return chain.proceed(request);
    }

}
